﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HistoryController.cs" company="">
//   Copyright (c) 2010/2011 All Right Reserved
// </copyright>
// <summary>
//   Contains HistoryController class declaration.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace IBupro.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;

    using IBupro.Controllers.Classes;

    using iBuproModel;
    using iBuproModel.Repositories.Interfaces;

    /// <summary>
    /// This controller contains actions related to communication history of diplom project approving process.
    /// </summary>
    public class HistoryController : CustomController
    {
        /// <summary>
        /// Shows history hierarchy for diplom project
        /// </summary>
        /// <param name="id">id of diplom project</param>
        /// <returns></returns>
        [ChildActionOnly]
        [Authorize]
        public ActionResult Index(int id)
        {
            IUserRepository users = repositoryService.UserRepositoryCreateInstance();
            User user = users.GetUserByUserName(User.Identity.Name);
            
            IDiplomProjectRepository projects = repositoryService.DiplomProjectRepositoryCreateInstance();
            DiplomProject project = projects.First(p => p.Id == id);

            if (user.DepartmentPrincipalDiplomProjects.Contains(project) || user.LectorDiplomProjects.Contains(project))
            {
                IHistoryRepository history = repositoryService.HistoryRepositoryCreateInstance();

                List<History> list = history.GetHistoryForDiplomProject(id).ToList();

                return View(list);
            }
            
            return View();
        }
    }
}
